<?php
class block_cleanup extends block_base 
{
	public function init() 
    {
        $this->title   = get_string('title', 'block_cleanup');
        $this->version = 2013030201;
		$this->cron	   = 3600*12;
    }
	
	function preferred_width() {
        return 210;
    }
    
	function applicable_formats() {
        return array('all' => true, 'tag' => false);   // Needs work to make it work on tags MDL-11960
    }
	
    public function get_content() 
    {
        global $CFG;
		
		if ( !has_capability("block/cleanup:block_access", get_context_instance(CONTEXT_SYSTEM)))
		{
			return '';
		}
		
	    if ($this->content !== NULL) 
	    {
		    return $this->content;
	    }
	    	
        $this->content         =  new stdClass;
        $text = "<p align='center' ><a href='".$CFG->wwwroot."/blocks/cleanup/index.php"."'>"
				.get_string('launch_script', 'block_cleanup')."</a><p>";
        $this->content->text   = $text;
        return $this->content;
    }
    
    public function cron() 
    {
        global $CFG;
        mtrace("\n..............BLOCK_CLEANUP CRON SCRIPT HAS STARTED.............");
        if ( intval($CFG->block_cleanup_is_cron) )
		{
			require_once($CFG->libdir."/cleanup/lib.php");
			delete_inactive_data();
		}
        mtrace("\n..............BLOCK_CLEANUP CRON SCRIPT HAS FINISHED.............");
        return true;
    }
    
    function instance_allow_config() {
        return false;
    }
}
?>